package com.uroad.jilinpda.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.uroad.jilinpda.R;
import com.uroad.jilinpda.bleactivation.TopUpUtil;
import com.uroad.jilinpda.modle.CardInfoMDL;


/**
 * @创建者 wlw
 * @创建时间 2019/6/16 17:04
 * @描述
 */
public class OBUCardInfoFragment extends Fragment {
    private View view;
    TextView tvCardIdentification;
    TextView tvCardType;
    TextView tvCardVersion;
    TextView tvCardArea;
    TextView tvCardNo;
    TextView tvCardBalance;
    TextView tvStartDate;
    TextView tvEndDate;
    TextView tvPlateNo;
    TextView tvUserType;
    TextView tvPlateColor;
    TextView tvCarType;

    private String file0015 = "";
    private String cardBalance = "";
    private CardInfoMDL mdl;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.view_obu_car_info, null);
        //        ButterKnife.bind(view);
        initView();
        SetData();
        return view;
    }

    private void initView() {
        tvCardIdentification = view.findViewById(R.id.tvCardIdentification);
        tvCardType = view.findViewById(R.id.tvCardType);
        tvCardVersion = view.findViewById(R.id.tvCardVersion);
        tvCardArea = view.findViewById(R.id.tvCardArea);
        tvCardNo = view.findViewById(R.id.tvCardNo);
        tvCardBalance = view.findViewById(R.id.tvCardBalance);
        tvStartDate = view.findViewById(R.id.tvStartDate);
        tvEndDate = view.findViewById(R.id.tvEndDate);
        tvPlateNo = view.findViewById(R.id.tvPlateNo);
        tvUserType = view.findViewById(R.id.tvUserType);
        tvPlateColor = view.findViewById(R.id.tvPlateColor);
        tvCarType = view.findViewById(R.id.tvCarType);
    }

    private void SetData() {
        setContent(file0015,cardBalance);
    }

    public void setContent(String file0015, String cardBalance) {
        if (!TextUtils.isEmpty(file0015) && file0015.length() > 62) {
            if (tvCardIdentification != null && tvCardType != null && tvCardArea != null && tvCardVersion != null && tvCardNo != null && tvStartDate != null && tvPlateNo != null) {
                mdl = TopUpUtil.getCardInfo(file0015.substring(8));
                if (mdl != null) {
                    tvCardIdentification.setText(mdl.getCardFrom());
                    tvCardType.setText(mdl.getCardType());
                    tvCardArea.setText(mdl.getCardArea());
                    tvCardVersion.setText(mdl.getCardVersion());
                    tvCardNo.setText(mdl.getCardNumber());
                    tvStartDate.setText(mdl.getStartDate());
                    tvEndDate.setText(mdl.getEndDate());
                    tvPlateNo.setText(mdl.getPlateNum());
                    tvUserType.setText(mdl.getUserType());
                    tvPlateColor.setText(mdl.getPlateColor());
                    tvCarType.setText(mdl.getCarType());
                    tvCardBalance.setText(cardBalance);
                }
            } else {
                this.file0015 = file0015;
                this.cardBalance = cardBalance;
            }
        }
    }
}
